package com.cokoyan.game.afts;

import java.util.HashMap;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

public class GameSounds {
	
	public static final int SOUND_EXPLOSION	 		= 1;
	public static final int SOUND_BONUS	 			= 2;
	public static final int SOUND_GAMEOVER	 		= 3;
	public static final int SOUND_CLICK		 		= 4;
	public static final int SOUND_SHOOT		 		= 5;
	public static final int SOUND_SHOOT2		 	= 6;
	public static final int SOUND_START		 		= 7;
	public static final int SOUND_SHIELD		 	= 8;
	public static final int SOUND_SHOOT3		 	= 9;
	
	private SoundPool soundPool;
	private HashMap<Integer, Integer> soundPoolMap;
	private Context m_context;
	
	private boolean mSound;
	
	public GameSounds(Context _context, boolean _sound){
		 m_context = _context;
		 mSound = _sound;
		 
		 
		 initSounds();
	}
	
	private void initSounds() {
	     if(mSound){
	    	 soundPool = new SoundPool(6, AudioManager.STREAM_MUSIC, 0);
	    	 soundPoolMap = new HashMap<Integer, Integer>();
		     soundPoolMap.put(SOUND_EXPLOSION, soundPool.load(m_context, R.raw.boom, 1));
		     soundPoolMap.put(SOUND_BONUS, soundPool.load(m_context, R.raw.bonus, 1));
		     soundPoolMap.put(SOUND_GAMEOVER, soundPool.load(m_context, R.raw.gameover, 1));
		     soundPoolMap.put(SOUND_CLICK, soundPool.load(m_context, R.raw.click, 1));
		     soundPoolMap.put(SOUND_SHOOT, soundPool.load(m_context, R.raw.shoot, 1));
		     soundPoolMap.put(SOUND_SHOOT2, soundPool.load(m_context, R.raw.shoot2, 1));
		     soundPoolMap.put(SOUND_START, soundPool.load(m_context, R.raw.start, 1));
		     soundPoolMap.put(SOUND_SHIELD, soundPool.load(m_context, R.raw.shield, 1));
		     soundPoolMap.put(SOUND_SHOOT3, soundPool.load(m_context, R.raw.shoot3, 1));
	     }
	}
	
	public void setSound(boolean s){
		mSound = s;
	}
	          
	public void playSound(int sound) {
		if(mSound){
			AudioManager mgr = (AudioManager)m_context.getSystemService(Context.AUDIO_SERVICE);
	     	int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
	     	soundPool.play(soundPoolMap.get(sound), streamVolume, streamVolume, 1, 0, 1f);
	     	
		}
	}
}
